<?php
/**
 * Created by PhpStorm.
 * User: bigniu
 * Date: 2020-01-25
 * Time: 16:00:40
 */

namespace app\admin\controller;


class TimeLine extends Admin
{

    public function getList(){
        $page = input("page/i", 1) <= 1 ? 1 : input("page/i", 1);
        $timeLineList =  Db("time_line")->page($page,10)->order("time desc")->select();
        if(!$timeLineList){
            return error("暂无更多数据");
        }
        return success("成功",$timeLineList);
    }
    public function postUpdate(){
        $id = input("id");
        $title = input("title");
        $content = input("content");
        $form = input("form");
        $src = input("src");
        $time =input("time");
        $data = [
            'title'=>$title,
            'content'=>$content,
            "form"=>$form,
            "src"=>$src,
            "time"=>$time
        ];
        $res = Db("time_line")->where(['id'=>$id])->update($data);
        if($res){
            config("update_time",TIME);
            return success("修改成功");
        }
        return error("修改失败");
    }
    public function postAdd(){
        $title = input("title");
        $content = input("content");
        $form = input("form");
        $src = input("src");
        $time =input("time");
        $data = [
            'title'=>$title,
            'content'=>$content,
            "form"=>$form,
            "src"=>$src,
            "time"=>$time,
            'create_time'=>TIME
        ];
        $res = Db("time_line")->insert($data);
        if($res){
            return success("添加成功");
        }
        return error("添加失败");
    }
    public function postDel(){
        $ids = input("ids/a");
        Db("time_line")->whereIn('id', $ids)->delete();
        return success("删除成功");
    }
}